/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = run_cunit.c                                        */
/*  NOTE      =                                                    */
/*  DATE      = 2014/09/30 by songbb                               */
/*******************************************************************/

#include <stdio.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"

int run_cunit(FunType fp)
{
    //CU_initialize_registry 注册函数注册一个用例返回CUE_系列异常值
    if( CUE_SUCCESS != CU_initialize_registry())
    {
        return CU_get_error();
    }

    //CU_get_registry 返回注册到用例指针
    assert(NULL != CU_get_registry());

    //检测是否在执行
    assert(!CU_is_test_running());

    //调用测试模块完成测试用例
	if (0 != fp())
    {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /**** Basic Mode ********************/
    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();
    /************************************/

    //调用完毕清除注册信息
    CU_cleanup_registry();

    return 0;
}
